
<?php

if (!empty($_SESSION['login'])&&!empty($_SESSION['email'])){

    $db = new Mypdo();
if(empty($_POST)){

    ?>

    <h1>Crée personne</h1>

    <form method="post" action="#">

        <p>
        <h3>Identité</h3>
        <label for="genre_pers">Genre :</label><select name="genre_pers" id="genre_pers" required="required">
            <option></option>
            <option value="M">M.</option>
            <option value="Mme">Mme.</option>
            <option value="Mlle">Mlle.</option>
        </select>
        <label for="nom_pers">Nom:</label><input name="nom_pers" type="text" id="nom_pers" required="required" />
        <label for="prenom_pers">Prenom :</label><input type="text" name="prenom_pers" id="prenom_pers" required="required" /><br />

        </p>
        <p>
            <?php include_once('Form_adresse.inc.php'); ?>
        </p>
        <p>
        <h3>Contact</h3>
        <label for="num_fix_pers">Numero fix</label><input name="num_fix_pers" type="text" id="num_fix_pers" required="required" />
        <label for="num_port_pers">Numero portable :</label><input type="text" name="num_port_pers" id="num_port_pers" /><br />
        <label for="email_pers">Email :</label><input type="text" name="email_pers" id="email_pers"  />
        </p>

        <p><input type="reset" value="Annuler" /><input type="submit" value="Valider" /></p>
    </form>

<?php }else{
    $pers = new Personne($_POST);
    $pers->setAdressePers(new Adresse($_POST));
   // var_dump($pers);

    $persManager = new PersonneManager($db);
    $id_pers = $persManager->add($pers);
    $partManager = new PartageManager($db);
    $partManager->add(array('id_loca'=> $_GET['id'],'id_pers'=>$id_pers));
    header('Location: index.php?page=114&id='.$_GET['id']);
}
}else{
    header('Location: index.php');
}